package net.peihuan.service.impl;

import net.peihuan.dao.CategoryMapper;
import net.peihuan.entity.Category;
import net.peihuan.service.CategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {


    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> findAllWithArticles() {
        return categoryMapper.selectAllCategorysWithArticles();
    }

    @Override
    public List<Category> findAll() {
        return categoryMapper.selectAllCategorys();
    }

    @Override
    public int save(Category category) {
        return categoryMapper.insert(category);
    }


    @Override
    public int delete(int id) {
        return categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Category find(int id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public int update(Category category) {
        return categoryMapper.updateByPrimaryKeySelective(category);
    }

    @Override
    public int count() {
        return categoryMapper.count();
    }
}
